package com.sikaryofficial.backend.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sikaryofficial.backend.constant.TagStatus;
import com.sikaryofficial.backend.domain.dto.req.information.ArticleTagReq;
import com.sikaryofficial.backend.domain.entity.ArticleTag;
import com.sikaryofficial.backend.mapper.ArticleTagMapper;
import com.sikaryofficial.backend.service.IArticleTagService;
import com.sikaryofficial.common.security.utils.SecurityUtils;
import com.sikaryofficial.system.api.model.infomation.TopicObjVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;

/**
 * 文章标签Service业务层处理
 *
 * @author qinjinyuan
 * @date 2025-04-27
 */
@Service
public class ArticleTagServiceImpl extends ServiceImpl<ArticleTagMapper, ArticleTag> implements IArticleTagService {
    @Autowired
    private ArticleTagMapper articleTagMapper;

    @Override
    public void saveTag(ArticleTagReq articleTag) {
        ArticleTag entity = new ArticleTag();
        entity.setArticleTagId(IdWorker.getId());
        entity.setArticleId(articleTag.getArticleId());
        entity.setTenantId(0);
        entity.setCreatedBy(SecurityUtils.getUserId());
        entity.setCreatedName(SecurityUtils.getUsername());
        entity.setUpdatedBy(SecurityUtils.getUserId());
        entity.setDeletedVersion(0L);
        entity.setTagEnable(articleTag.getTagEnable());
        articleTagMapper.saveTag(entity);
    }

    @Override
    public ArticleTag getEnabledArticleTag() {
	    return this.lambdaQuery()
	            .eq(ArticleTag::getTagEnable, TagStatus.ENABLED.getCode())
	            .eq(ArticleTag::getDeletedVersion, 0L)
	            .one();
    }
}
